import { createRouter, createWebHashHistory } from "vue-router";
/* Layout */
import Layout from "@/views/layout";

// 自动导入所有模块
const modulesFiles = require.context("./modules", true, /\.js$/);
const moduleRoutes = modulesFiles.keys().reduce((routes, modulePath) => {
  const value = modulesFiles(modulePath);
  return [...routes, ...value.default];
}, []);
const routes = [
  {
    path: "/",
    redirect: "/dashboard"
  },
  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    meta: { title: "首页", icon: "dashboard" },
    hidden: true,
    children: [
      ...moduleRoutes // 导入所有模块路由
    ]
  },
  {
    path: "/:pathMatch(.*)*",
    name: "NotFound",
    component: () => import("@/views/NotFound.vue")
  }
  // {
  //   path: '/login',
  //   name: 'Login',
  //   component: () => import('@/views/Login.vue')
  // },
  //   {
  //     path: '*',
  //     redirect: '/monitor'
  // }
];

const router = createRouter({
  history: createWebHashHistory(),
  routes
});

export default router;
